﻿using System;
using CompactMapper.Orm.Annotations;
using CompactMapper.Orm.UnitOfWork.Mappings.Meta.PropertyInfos;
using CompactMapper.Orm.UnitOfWork.Mappings.Meta.PropertyInfos.Columns;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CompactMapper.Orm.Tests.Columns
{
    [TestClass]
    public class DoubleColumnMappingTests : OrmInMemoryTest
    {
        [Table]
        public class TableWithDoubleColumn
        {
            [DoubleColumn]
            public double DoubleColumn { get; set; }
        }

        [TestMethod]
        public void DoubleColumnMappingTests_FromSql()
        {
            const double maxValue = double.MaxValue;
            const double minValue = double.MaxValue;
            const double positiveInteger = 1;
            const double negativeInteger = -11;
            const double positiveReal = Math.PI;
            const double negativeReal = -Math.PI;


            var propertyInfo = typeof(TableWithDoubleColumn).GetProperty("DoubleColumn");
            var column = new TextColumn(new PropertyInfoPersistenceAttributePair(propertyInfo, new CharColumnAttribute()));



            Assert.AreEqual(maxValue, column.FromSqLiteObject(maxValue));
            Assert.AreEqual(minValue, column.FromSqLiteObject(minValue));
            Assert.AreEqual(positiveInteger, column.FromSqLiteObject(positiveInteger));
            Assert.AreEqual(negativeInteger, column.FromSqLiteObject(negativeInteger));
            Assert.AreEqual(positiveReal, column.FromSqLiteObject(positiveReal));
            Assert.AreEqual(negativeReal, column.FromSqLiteObject(negativeReal));
        }
    }
}
